package com.hon.legionnaire.negocio.vo;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;


@Entity
@Table(name = "condicaoPagamento")
@SequenceGenerator(name = "condicaoPagamento_seq", sequenceName = "condicaoPagamento_cod_condicaoPagamento_seq", allocationSize = 1)
@NamedQueries ({
	@NamedQuery(name = "loadAllCondicaoPagamento", query = "from CondicaoPagamentoVO"),
	@NamedQuery(name = "findCondicaoPagamento", query = "from CondicaoPagamentoVO as p where p.codigo = :codigo"),
	@NamedQuery(name = "findDuplicatedCondicaoPagamento", query = "from CondicaoPagamentoVO as p where p.descricao = :descricao and p.codigo != :codigo")
})
public class CondicaoPagamentoVO implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "cod_condicaoPagamento")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "condicaoPagamento_seq")
	private int codigo;
	
	@Column(name = "descricao")
	private String descricao;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "cod_forma_pagamento")
	@Fetch(FetchMode.JOIN)
	private FormaPagamentoVO formaPagamentoVO;
	
	@OneToMany(mappedBy = "condicaoPagamentoVO", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	@Fetch(FetchMode.SUBSELECT)
	private List <ParcelaVO> parcelas;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column (name = "data_criacao")
	private Date dataCriacao;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column (name = "data_alteracao")
	private Date dataAlteracao;
	
	
	public CondicaoPagamentoVO() {
		
	}
	
	public CondicaoPagamentoVO(int codigo, String descricao, int ddi) {
		this.codigo = codigo;
		this.descricao = descricao;
	}
	
	
	public FormaPagamentoVO getFormaPagamentoVO() {
		return formaPagamentoVO;
	}

	public void setFormaPagamentoVO(FormaPagamentoVO formaPagamentoVO) {
		this.formaPagamentoVO = formaPagamentoVO;
	}

	public List<ParcelaVO> getParcelas() {
		return parcelas;
	}

	public void setParcelas(List<ParcelaVO> parcelas) {
		this.parcelas = parcelas;
	}

	public int getCodigo() {
		return codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public void setDataCriacao(Date dataCriacao) {
		this.dataCriacao = dataCriacao;
	}

	public Date getDataCriacao() {
		return dataCriacao;
	}

	public void setDataAlteracao(Date dataAlteracao) {
		this.dataAlteracao = dataAlteracao;
	}

	public Date getDataAlteracao() {
		return dataAlteracao;
	}
		
}